package com.guan.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guan.commonutils.R;
import com.guan.eduservice.entity.EduCourse;
import com.guan.eduservice.entity.EduTeacher;
import com.guan.eduservice.service.EduCourseService;
import com.guan.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Date: 2023/3/13 12:53
 * @Author: 管奇安
 * @Description:
 */
@RestController
@RequestMapping("cmsservice/indexFront/*")
@CrossOrigin
public class IndexFrontContrller {

    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;

    /**
     * @date: 2023/3/13 13:02
     * @author: 管奇安
     * @description: 查询热门课程 讲师
     * @param: []
     * @return: com.guan.commonutils.R
     **/
    @GetMapping("index")
    public R index(){

        //查询前8个热门课程
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("buy_count");
        courseQueryWrapper.orderByDesc("view_count");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(courseQueryWrapper);

        //查询前4个名师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id");
        courseQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherQueryWrapper);

        return R.ok()
                .data("courseList",courseList)
                .data("teacherList",teacherList);
    }


}
